<template>
  <div>
    <el-table :data="tableData" border size="mini" style="width: 100%">
      <el-table-column
        v-for="item in columnArr"
        :key="item.value"
        :prop="item.value"
        :label="item.label"
        align="center"
      >
      </el-table-column>
      <el-table-column width="180" align="center">
        <template slot="header" slot-scope="scope">
          <el-button type="warning" size="mini" @click="addFn(scope.row)"
            >增加</el-button
          >
        </template>

        <template #default="{ row }">
          <el-button type="primary" size="mini" @click="deleteFn(row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  props: {
    columnArr: {
      type: Array
    },
    tableData: {
      type: Array
    }
  },
  data () {
    return {}
  },
  methods: {
    addFn (row) {
      this.tableData.push({
        date: '测试',
        name: '测试' + Math.random(),
        address: '测试',
        id: Math.random()
      })
    },
    deleteFn (row) {
      const index = this.tableData.findIndex((item) => item.id === row.id)
      this.tableData.splice(index, 1)
    }
  }
}
</script>

<style>
</style>
